package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportStaffGrade;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportStaffGradeDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2020-01-11 22:20:30
 */
public class TransportStaffGradeConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportStaffGradeConverts.class);

    public static List<TransportStaffGradeDTO> convert(List<TransportStaffGrade> transportStaffGradeList) {
        if (CollectionUtils.isEmpty(transportStaffGradeList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportStaffGradeDTO> transportStaffGradeListResult = Lists.newArrayList();
        for (TransportStaffGrade transportStaffGrade : transportStaffGradeList) {
            transportStaffGradeListResult.add(convert(transportStaffGrade));
        }
        return transportStaffGradeListResult;
    }

    public static TransportStaffGradeDTO convert(TransportStaffGrade transportStaffGrade) {
        try {
            return BeanUtils.copy(transportStaffGrade, TransportStaffGradeDTO.class);
        } catch (Exception e) {
            LOG.error("TransportStaffGrade到TransportStaffGradeDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportStaffGrade到TransportStaffGradeDTO转换失败", e);
        }
    }

    public static TransportStaffGrade convert(TransportStaffGradeDTO transportStaffGradeDTO) {
        try {
            return BeanUtils.copy(transportStaffGradeDTO, TransportStaffGrade.class);
        } catch (Exception e) {
            LOG.error("TransportStaffGradeDTO到TransportStaffGrade转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportStaffGradeDTO到TransportStaffGrade转换失败", e);
        }
    }
}